#ifndef STORAGE_FSM_FSM_H
#define STORAGE_FSM_FSM_H 1

#include <unistd.h>

#include <common/macro/build.h>
#include <common/io.h>

#include <storage/page.h>
#include <storage/itempointer.h>

typedef struct fsm_item_t {
	enum page_type_e page_type;
	page_size_t page_size;
} fsm_item_t;

typedef struct fsm_t {
	fsm_item_t *items;
	size_t items_c;
} fsm_t;

API_LIBLOCAL fsm_t *fsm_new();
API_LIBLOCAL void fsm_destroy(fsm_t *);
API_LIBLOCAL void fsm_flush(fsm_t *);
API_LIBLOCAL inline ssize_t fsm_item_size();
API_LIBLOCAL int fsm_serialize_file(fsm_t *, iohandle_t);
API_LIBLOCAL fsm_t *fsm_deserialize_file(iohandle_t, int);
API_LIBLOCAL int fsm_get_fitting_page(fsm_t *, page_size_t, enum page_type_e, page_number_t *, page_number_t *);
API_LIBLOCAL void fsm_set_page(fsm_t *, page_number_t, enum page_type_e, page_size_t);
API_LIBLOCAL inline int fsm_seek_to_page(iohandle_t, page_number_t);

#endif
